/***************************************************************************
 *   Copyright (C) 2009 by Bernhard Neuhofer   *
 *   mail@bneu.at   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#ifndef __MESSAGEHANDLER_H
#define __MESSAGEHANDLER_H

#include "message.h"

/**
* @brief Interface for every concrete message handler implementation (Strategy pattern).
* A message handler is attached to a submodel manager and acts as communication facility 
* for all LPs of the submodel.
*/
class MessageHandler
{
public:
  /**
   * Sends a message to a given LP by invoking the <code>receiveMessage</code>
   * method of the associated message handler on the receiver.
   * @param message The message to send
   */
virtual  void sendMessage(Message * message)=0;

  /**
   * Remotly callable method for message reception.
   * @param message The mesage to receive from a remove Messagehandler
   */
  virtual void receiveMessage(Message * message)=0;

  /**
   * Registers a LP as local and creates an empty buffer for it.
   * @param id of the LP
   */
  virtual void addClient(unsigned int id)=0;

  /**
   * Tests if the buffer of a given LP is empty
   * @param id of the LP
   * @return bool
   */
  virtual bool bufferEmpty(unsigned int id)=0;

  /**
   * Returns the size of a buffer. Used for debugging.
   * @param id Which buffer
   * @return size of the buffer
   */
  virtual unsigned int bufferSize(unsigned int id)=0;
  
  /**
   * Counts the unread message in all buffers. Used to correct GVT algo. at
   * startup ( nr of initial message is subtracted from message difference counter).
   * @return Total unread message
   */
  virtual unsigned int totalMsgs()=0;

  /**
   * Reads the first message from the buffer of a given LP and removes it from 
   * the buffer. Returns <code>NULL</code> if buffer is empty.
   * @param id of the LP
   * @return Next message or NULL if empty
   */
  virtual Message * readBuffer(unsigned int id)=0;

private:


};

#endif